package com.atguigu.kaiser;

import com.sun.org.apache.xml.internal.security.utils.Base64;
import sun.security.jca.GetInstance;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;

/**
 * @program: IDEAcode
 * @description:
 * @author: Mr.zjx
 * create: 2021-08-04-15-31
 **/
public class DesAesDemo {
    public static void main(String[] args) throws Exception {
        String input = "硅谷";
        String key = "12345678";//des加密必须是八位
        String algorithm = "DES";
        String transformation = "DES";
        //Cipher:获取加密对象
        Cipher cipher = Cipher.getInstance(transformation);
                                    //秘钥规则：key的字节数组       算法
        SecretKeySpec sks = new SecretKeySpec(key.getBytes(), algorithm);
                    //加密模式
        cipher.init(Cipher.ENCRYPT_MODE,sks);
        //加密
        byte[] bytes = cipher.doFinal(input.getBytes());
        //base64编码
        String encode = Base64.encode(bytes);
        System.out.println(encode);
    }
}
